|
|
|
|
|
|
|
'Code to create a new file goes here
MsgBox "Creating a new file . . ."
Case "REPORT"
'Create a report with the current region
Call MakeReport
End Select
End Sub
Private Sub tbrDemo_ButtonMenuClick(ByVal ButtonMenu As ComctlLib.ButtonMenu)
'Create a report using the newly selected region
sCurrentRegion = UCase(ButtonMenu.Text)
ButtonMenu.Parent.Caption = sCurrentRegion
Call MakeReport
End Sub
Sub MakeReport()
Dim sTemp As String
'If no region selected, use WEST as default
If Trim(sCurrentRegion) = "" Then
sCurrentRegion = "WEST"
End If
sTemp = "Creating report for " & sCurrentRegion
sTemp = sTemp & " Region . . ."
MsgBox sTemp
'Actual report-creating lines go here . . .
End Sub |
|
|
|
|
|
|
|
|
Once you have entered this code, run the program and examine the behavior of the toolbar buttons. |
|
|
|
|
|
|
|
|
The procedures being called are actually the Click event procedures of menu items. With these procedures being called, you can code an action once and then call it from either the menu or the toolbar. Doing so makes it easier to maintain your code because changes or corrections have to be made in only a single location. Also, note the introduction of the Select Case statement, which is more readable than a nested If statement. You learn about it in more detail in a later chapter. |
|
|
|
|
|
|
|
|
See ''Using Select Case," p. 207 |
|
|
|
|
|
|
|
|
Creating a Toolbar with Code |
|
|
|
|
|
|
|
|
Although you can set up a toolbar in the design environment, you can also set up and change a toolbar at runtime with program code. To use the Toolbar and other common controls successfully, you need to understand the concept of collections. |
|
|
|
|
|
|
|
|
Understanding Collections |
|
|
|
|
|
|
|
|
A collection is a group of objects. In the case of the ImageList control, you will find a collection called ListImages. The objects stored in this particular collection are the images in the ImageList control. By manipulating the ListImages collection from code, you can add, remove, and change images. |
|
|
|
|
|